cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

PROJECT(CAEStdConvertor)

if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
	SET(CMAKE_DEBUG_POSTFIX "_d")
endif()

include_directories(${CMAKE_SOURCE_DIR}/parsebdf)
include_directories(${CMAKE_SOURCE_DIR}/parseinp)

if(ENABLE_ODB)
    include_directories(${CMAKE_SOURCE_DIR}/parseodb)
endif()
if(ENABLE_CGNS)
    include_directories(${CMAKE_SOURCE_DIR}/parsecgns)
endif()

file(GLOB cdb_h ${CMAKE_SOURCE_DIR}/parsecdb/*.h)
file(GLOB cdb_cpp ${CMAKE_SOURCE_DIR}/parsecdb/*.cpp)
set(CDBCODE
    ${cdb_h}
    ${cdb_cpp}
)
file(GLOB bdf_h ${CMAKE_SOURCE_DIR}/parsebdf/*.h)
file(GLOB bdf_cpp ${CMAKE_SOURCE_DIR}/parsebdf/*.cpp)
set(BDFCODE
    ${bdf_h}
    ${bdf_cpp}
)
file(GLOB inp_h ${CMAKE_SOURCE_DIR}/parseinp/*.h)
file(GLOB inp_cpp ${CMAKE_SOURCE_DIR}/parseinp/*.cpp)
set(INPCODE
    ${inp_h}
    ${inp_cpp}
)

set(Generate_code
	main.cpp
	main.h
	GeneralMethod.h
        core_function.cpp
        core_function.h
    ${CMAKE_CURRENT_SOURCE_DIR}/Icon/icon.rc
    ${CDBCODE}
    ${BDFCODE}
    ${INPCODE}
    )
    
add_executable(${PROJECT_NAME} ${Generate_code})
target_link_libraries(${PROJECT_NAME}
    ${PYTHON_LIBS}
    ${VTK_LIBRARIES}
    )
if(UNIX)
    target_link_libraries(${PROJECT_NAME}
        stdc++fs
    )
endif()

if(ENABLE_ODB)
    target_link_libraries(${PROJECT_NAME}
        ParseODB
    )
endif()
if(ENABLE_CGNS)
    target_link_libraries(${PROJECT_NAME}
        ParseCGNS
    )
endif()

add_library(${PROJECT_NAME}_so SHARED
        GeneralMethod.h
        core_function.cpp
        core_function.h
        ${CDBCODE}
        ${BDFCODE}
    ${INPCODE}
)
if(UNIX)
    target_link_libraries(${PROJECT_NAME}_so
            stdc++fs
            ParseODB
            ParseCGNS
            ${PYTHON_LIBS}
            ${VTK_LIBRARIES}
    )
endif()

# 将dll和lib放置到指定目录下
if(WIN32)
    set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${WORK_ROOT_DIR})
    set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${WORK_ROOT_DIR})
    set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${WORK_ROOT_DIR})
else()
    set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${WORK_DIR})
    set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${WORK_DIR})
    set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${WORK_DIR})
endif()
